import { onMounted } from 'vue';
export default function useGetDom(page ?: any) {
	let query : any = null;
	onMounted(() => {
		if (page) {
			query = uni.createSelectorQuery().in(page);
		} else {
			query = uni.createSelectorQuery();
		}

	})
	const getDomInfo = (select : any) => {
		return new Promise((resolve, reject) => {
			query && query
				.select(select)
				.boundingClientRect((data : any) => {
					resolve(data)
				})
				.exec();
		})
	}
	const getDomScroll = (select : any) => {
		return new Promise((resolve, reject) => {
			query && query
				.select(select)
				.scrollOffset((data : any) => {
					resolve(data)
				})
				.exec();
		})
	}




	return { getDomInfo, getDomScroll, query };

}